package com.jianganming.facade;

public class FacadeTest2 {


    public static void main(String[] args) {
        //商品
        GiftInfo giftInfo = new GiftInfo("笔记本电脑");
        FacadeService facadeService = new FacadeService();
        //下单
        facadeService.exchange(giftInfo);
    }
}

//商品
class GiftInfo{
    private String name;

    public GiftInfo(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

//库存系统
class QualifyService{
    public boolean isAvailable(GiftInfo giftInfo){
        System.out.println("校验" +giftInfo.getName() + "积分通过,库存通过。");
        return true;
    }
}

//积分系统
class PaymentService{
    public boolean pay(GiftInfo giftInfo){
        System.out.println("扣减" +giftInfo.getName() + "积分成功。");
        return true;
    }
}
//物流系统
class ShippingService{
    public String delivery(GiftInfo giftInfo){
        System.out.println(giftInfo.getName() + "进入物流系统。");
        String shippingNumber = "666";
        return shippingNumber;
    }
}

//下单系统
class FacadeService{
    private QualifyService qualifyService;
    private PaymentService paymentService;
    private ShippingService shippingService;

    public FacadeService(){
        this.paymentService = new PaymentService();
        this.qualifyService = new QualifyService();
        this.shippingService = new ShippingService();
    }

    public void exchange(GiftInfo giftInfo){
        if(qualifyService.isAvailable(giftInfo)){
            if(paymentService.pay(giftInfo)){
                String shippingNumber = shippingService.delivery(giftInfo);
                System.out.println("物流系统下单成功，"+giftInfo.getName()+"物流单号是：" + shippingNumber);
            }
        }
    }
}